package com.javabasic.algorithm.leetcode;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @Author xiongmin
 * @Description //TODO
 * @Date 2020/7/11 22:26
 * @Version 1.0
 **/
public class CountOfSmallerNumbersAfterSelf {

    public List<Integer> countSmaller(int[] nums) {

        int len = nums.length;
        Integer[] count = new Integer[len];
        count[len-1] = 0;
        for (int i = len-2; i >= 0; i--) {
            count[i] = 0;
            if (count[i] == count[i+1]) {
                count[i] = count[i+1];
                continue;
            }
            for (int j = i + 1; j < len; j++) {
                if (nums[j] < nums[i]) {
                    count[i] ++;
                }
            }
        }
        return new ArrayList<>(Arrays.asList(count));
    }
}

